<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    // function List(){
    //     function ListNode(val) {
    //         this.val = val;
    //         this.next = null;
    //     }
    //     this.head = null;
    //     List.prototype.append = function (data){
    //         var newNode = new ListNode(data);
    //         if(this.head == null){
    //             this.head = newNode;
    //         }else{
    //             var current = this.head;
    //             while(current.next){
    //                 current = current.next;
    //             }
    //             current.next = newNode;
    //         }
    //     };
    //
    //     List.prototype.toString = function(){
    //       var current = this.head;
    //       var result = "";
    //       while(current){
    //           result += current.val +" ";
    //           current = current.next;
    //       }
    //
    //       return result;
    //     };
    // }
    function ListNode(val) {
                this.val = val;
                this.next = null;
    }


    var mergeTwoLists = function(l1, l2) {

        //遍历嵌套 遍历l1 并 遍历l2查找小于当前节点的元素
        //判断参数是否为空
        if(l1==null){
            return l2;
        }else if(l2==null){
            return l1
        }
        var current1 = l1,
            current2 = l2;
        var prev = null;
        //l1与l2的第一个元素之间相互比较
        while(current1){
            //在l2中遍历比current1小的元素，添加进l1中
            console.log("test");
            console.log((current2.val <= current1.val));
            console.log(current2.val);
            console.log(current1);
            while(current2.val <= current1.val){

                //第一次判断，需要改变l1指向
                if(prev==null){
                    prev = current2;
                    l1 = prev;
                    current2  = current2.next;
                    prev.next = current1;


                }else{
                    prev.next = current2;
                    var temp = current2;
                    current2 = current2.next;
                    temp.next = current1;
                }
                // 判断一下是否l2已经遍历完 current2指向l2中的尾元素
                if(current2 == null){return l1}



            }
            current1 = current1.next;

        }
        return l1


    };

 var l1_0 = new ListNode(1),
     l1_1 = new ListNode(2),
     l1_2 = new ListNode(4);
 l1_0.next = l1_1;
 l1_1.next = l1_2;

 var l2_0 = new ListNode(1),
     l2_1 = new ListNode(3);
     var tail = new ListNode(4);




</script>
</body>
</html>